<?php
class cardcafe
{
	public static function loadUrl($url,$post,$cookies)
	{
		$timeout=200;
		$ch = curl_init(); 
		curl_setopt($ch, CURLOPT_URL, $url); 
		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/6.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3"); 
		curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies); 
		curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies); 
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		$result = curl_exec($ch);
		curl_close($ch);
		return $result;
	}
	public static function loginCardCafe($cookies){
		self::logoutCardCafe();
		$url="http://cardrockcafe.biz/?s=login";
		$post="login=user&pass=pass";
		$login=self::loadUrl($url, $post,$cookies);
		return $login;
	}
	public static function logoutCardCafe(){
		$a=rand(1000,100000);
		$cookies="cookiesx/".$a."cookies.txt";
		$url="http://cardrockcafe.biz/?s=out";
		$logout=self::loadUrl($url, "0",$cookies);
		return TRUE;
	}
	public static function GetContents($string,$start,$end){
		$temp=explode($start,$string);
		$Result=explode($end,$temp[1]);
		return $Result[0];
	}
	public static function getBalanceCardCafe(){
		$a=rand(1000,100000);
		$cookies="../plan/cookiesx/".$a."cookies.txt";
		$login=self::loginCardCafe($cookies);
		if(!empty($login))
		{
			$start='Balance: <b>';
			$end='$</b>';
			$balance=self::GetContents($login, $start, $end);
			return $balance;
		}
		else 
		{
			return "erro";
		}
	}
	public static function searchCountryCardCafe(){
		$a=rand(1000,100000);
		$cookies="cookiesx/".$a."cookies.txt";
		$login=self::loginCardCafe($cookies);
		$url="http://cardrockcafe.biz/?s=cc";
		$loadCc=self::loadUrl($url, "0",$cookies);
		$start='<select name="country" id="country" onchange="ChangeCountry(this.value)">';
		$end='</select>';
		if(empty($loadCc))
		{
			return 0;
		}
		else 
		{
			$GetContents=self::GetContents($loadCc, $start, $end);
			$delimiter='</option>';
			$arryCountry=explode($delimiter,$GetContents);
			$totalCountry=count($arryCountry)-1;
			for($i=0;$i<$totalCountry;$i++)
			{
				$line=$arryCountry[$i];
				$start='<option value="';
				$end='">';
				$country_code=self::GetContents($line, $start, $end);
				$country_code=strtolower($country_code);
				$arrayReturn[]=$country_code;
			}
			return $arrayReturn;
		}
		
	}
	public static function searchCcCardCafe($country,$bin,$type,$price){
		$a=rand(1000,100000);
		$cookies="cookiesx/".$a."cookies.txt";
		$urlSearch="http://cardrockcafe.biz/?s=cc";
		if($bin==0)
		{
			$bin="";
		}
		if(!empty($Type))
		{
			$bin=$Type;
		}
		$post="country=$country&type=$type&bin=$bin&state=all&exp_month=any&exp_year=any&city=all&price=all&zip=&type=&search=Search";
		self::loginCardCafe($cookies);
		$getCcInfo=self::loadurl($urlSearch, $post,$cookies);
		if(empty($getCcInfo))
		{
			return 0;
		}
		else
		{
			$start='<table class="cc_table" width="100%">';
			$end='</table>';
			$soure=self::GetContents($getCcInfo, $start, $end);
			unset($getCcInfo);
			$delimiter='<tr>';
			$arrayInfo=explode($delimiter,$soure);
			$search=array('<td>','</td>','<input type="checkbox" name="ccs[]" value="','">','</tr>');
			$replace=array('','|','','','');
			$id=0;
			for($i=1;$i<count($arrayInfo);$i++)
			{
				$ccLine=str_replace($search, $replace, $arrayInfo[$i]);
				$arrayCc=explode("|",$ccLine);
				$ex=rtrim(trim($arrayCc[2]));
				$exM=substr($ex, 0,2);
				$exY="20".substr($ex, 3,2);
				$ArrReturn["$id"]['bin']=rtrim(trim($arrayCc[0]));
				$ArrReturn["$id"]['name']=rtrim(trim($arrayCc[1]));
				$ArrReturn["$id"]['exM']=$exM;
				$ArrReturn["$id"]['exY']=$exY;
				$ArrReturn["$id"]['city']=rtrim(trim($arrayCc[3]));
				$ArrReturn["$id"]['state']=rtrim(trim($arrayCc[4]));
				$ArrReturn["$id"]['country']=rtrim(trim($arrayCc[5]));
				$ArrReturn["$id"]['zip']=rtrim(trim($arrayCc[6]));
				$ArrReturn["$id"]['price']=$price;
				$ArrReturn[$id]['ccid']=rtrim(trim($arrayCc[8]));
				$id++;
			}
			return $ArrReturn;
		}
	}
	public static function addToCart($ccid,$cookies)
	{
		self::loginCardCafe($cookies);
		$Url="http://cardrockcafe.biz/?s=cart";
		$Post=NULL;
		foreach($ccid as $showCcId)
		{
			$Post=$Post."&ccs%5B%5D=".$showCcId;
		}
		$Post2="save=Add+to+cart";
		$Post=$Post2.$Post;
		$AddToCart=self::loadurl($Url, $Post,$cookies);
		return $AddToCart;
	}
	public static function CheckCcBefore($ccnum,$exm,$exy,$cookies)
	{
		$ex=substr($exy,2,2).$exm;
		$urlcheck="http://cardrockcafe.biz/?s=check&d=$ccnum|$ex";
		$ArrCcCheck=self::loadUrl($urlcheck, "0",$cookies);
		if(stristr($ArrCcCheck, "Approved")==TRUE)
		{
			return 1; // live
		}
		else if(stristr($ArrCcCheck, "Expired check")==TRUE)
		{
			return 3; // live
		}
		else if(stristr($ArrCcCheck, "Declined")==TRUE)
		{
			return 0; // die
		}
		else
		{
			return 2;
		}

	}
	public static function getCcCardCafe($quality,$price,$userID,$orderid)
	{
		$checkerId=buycc::findChecker("cardcf");
		$a=rand(1000,100000);
		$cookies="cookiesx/".$a."cookies.txt";
		self::loginCardCafe($cookies);
		$url="http://cardrockcafe.biz/?s=my";
		$myOrders=self::loadUrl($url, "0",$cookies);
		if(empty($myOrders))
		{
			return 0; 
		}
		else 
		{
			$start='<table class="my_cc_table" width="100%">';
			$end='</div>';
			$soure=self::GetContents($myOrders, $start, $myOrders);
			$delimiter="<tr>";
			$arrayCcSoure=explode($delimiter,$soure);
			$search=array('<td>','</td>');
			$replace=array("","|");
			for($i=1;$i<=$quality;$i++)
			{
				$ccSoure=$arrayCcSoure[$i];
				$ccSoure=str_replace($search, $replace, $ccSoure);
				$arrayPart=explode("|",$ccSoure);
				$ccNum=rtrim(trim($arrayPart[1]));
				$ex=rtrim(trim($arrayPart[2]));
				$exM=substr($ex, 0,2);
				$exY="20".substr($ex, 2,2);
				$checkBefore=self::CheckCcBefore($ccNum, $exM, $exY,$cookies);
				$ccv=rtrim(trim($arrayPart[3]));
				$country=rtrim(trim($arrayPart[8]));
				$ccNumHash=hash::hashccv($ccNum, $exM, $exY, $ccv);
				$search=array($ccNum,$ex,$ccv,$country,"[bad]","[ok]","Expired check");
				$replace=array("","","","","","","");
				$others=str_replace($search, $replace, $ccSoure);
				$insert=database::Insert("ccinfo", array(
				'CCnumber' => $ccNumHash,
				'ExMonth' => $exM,
				'ExYear' => $exY,
				'CCV2' => $ccv,
				'Others' => $others,
				'country' => $country,
				'pricesell' => $price,
				'userid' => $userID,
				'orderid' => $orderid,
				'site' => 'cardcf',
				'checker_id' => $checkerId
				));
				return TRUE;
			}
		}
		
	}
	public static function checkOutCardCafe($ccid,$quality,$price,$userID,$orderid)
	{
		$a=rand(1000,100000);
		$cookies="cookiesx/".$a."cookies.txt";
		$add2Cart=self::addToCart($ccid,$cookies);
		$UrlCheckout="http://cardrockcafe.biz/?s=cart&checkout=1";
		$Checkout=self::loadurl($UrlCheckout, "0",$cookies);
		if(stristr($Checkout,"Checkout")==TRUE)
		{
			return FALSE;
		}
		else 
		{
			$getCc=self::getCcCardCafe($quality, $price, $userID, $orderid);
			return $getCc;
		}
	}
	public static function CheckCc($ccnum,$exm,$exy)
	{
		$a=rand(1000,100000);
		$cookies="plan/cookiesx/".$a."cookies.txt";
		self::loginCardCafe($cookies);
		$urlcheck="http://cardrockcafe.biz/?s=my";
		$Check=self::loadurl($urlcheck, "0",$cookies);
		$start='<td id="'.$ccnum.'">';
		$end="</td>";
		$ArrCcCheck=self::GetContents($Check, $start, $end);
		if(stristr($ArrCcCheck, "[ok]")==TRUE)
		{
			return 1; // live
		}
		else if(stristr($ArrCcCheck, "[bad]")==TRUE)
		{
			return 0; // die
		}
		else if(stristr($ArrCcCheck,"Expired check")==TRUE)
		{
			return 3;// expert timr
		}
		else
		{
			return 2;
		}

	}
}

?>